home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10398 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: unixg.ubc.ca!news
  2. From: jamesdf@unixg.ubc.ca (James Fairweather)
  3. Newsgroups: comp.lang.c++
  4. Subject: Pointer to non-static function
  5. Date: Thu, 07 Mar 1996 23:49:16 GMT
  6. Organization: Resnet
  7. Message-ID: <4hnsfs$cp2@nntp.ucs.ubc.ca>
  8. NNTP-Posting-Host: srtb0411a01.resnet.ubc.ca
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I am attempting to make some code I've written more elegant by using a
  12. pointer to a function.  Here's how I declare the pointer:
  13.  
  14.     double (*f)(double);
  15.  
  16. Now I'd like to make f point to one of two functions, one declared as:
  17.  
  18.     double CFunction::Calculate(double);
  19.  
  20. and the other as:
  21.  
  22.     double CEquation::Calculate(double);
  23.  
  24. Neither are static, and CEquation and CFunction are not related by
  25. inheritance.  Nor can they be, since CEquation contains a list of
  26. CFunctions.
  27.  
  28. At compile time, the compiler issues an error, "cannot convert from
  29. double (CFunction::*)(double) to double (__cdecl *)(double)" and
  30. "cannot convert from double (CEquation::*)(double) to double (__cdecl
  31. *)(double)".
  32.  
  33. This looks suspiciously like a typecasting problem to me.  I'm
  34. wondering if what I'm attempting to do is possible, and if so, how to
  35. do it.  What is the correct way to do the typecast, if that is the
  36. problem?  Any help is much appreciated.
  37.  
  38.     James
  39.  
  40.  
  41.